<?php
App::uses('AppController', 'Controller');
class QuestionQuizzesController extends AppController {

	var $name = 'QuestionQuizzes';

	function index() {
		$this->QuestionQuiz->recursive = 0;
		$this->set('questionQuizzes', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid question quiz', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('questionQuiz', $this->QuestionQuiz->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->QuestionQuiz->create();
			if ($this->QuestionQuiz->save($this->data)) {
				$this->Session->setFlash(__('The question quiz has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The question quiz could not be saved. Please, try again.', true));
			}
		}
		$questions = $this->QuestionQuiz->Question->find('list');
		$quizzes = $this->QuestionQuiz->Quiz->find('list');
		$this->set(compact('questions', 'quizzes'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid question quiz', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->QuestionQuiz->save($this->data)) {
				$this->Session->setFlash(__('The question quiz has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The question quiz could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->QuestionQuiz->read(null, $id);
		}
		$questions = $this->QuestionQuiz->Question->find('list');
		$quizzes = $this->QuestionQuiz->Quiz->find('list');
		$this->set(compact('questions', 'quizzes'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for question quiz', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->QuestionQuiz->delete($id)) {
			$this->Session->setFlash(__('Question quiz deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Question quiz was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>
